package com.hlf.common.page;

import java.util.List;
import java.util.Map;

/**
 * 公共分页返回实体类
 */
public class PageReturn<T> {

    public PageReturn() {

    }

    /**
     * 分页构造函数,不查询总记录数
     *
     * @param list   结果集
     * @param page   分页对象
     * @param entity 请求时的参数对象,页面可通过该对象获取搜索的条件
     */
    public PageReturn(List<T> list, Page page, T entity) {
        this.entityList = list;
        this.currentPage = page.getCurrentPage();
        this.pageSize = page.getPageSize();
        this.entity = entity;
    }

    /**
     * 分页构造函数,查询总记录数
     *
     * @param list   结果集
     * @param count  总记录数
     * @param page   分页对象
     * @param entity 请求时的参数对象,页面可通过该对象获取搜索的条件
     */
    public PageReturn(List<T> list, int count, Page page, T entity) {
        this.entityList = list;
        this.totalRecord = count;
        this.currentPage = page.getCurrentPage();
        this.pageSize = page.getPageSize();
        this.entity = entity;
    }

    /**
     * 总记录数
     */
    private int totalRecord = 0;

    /**
     * 总页数
     */
    @SuppressWarnings("unused")
    private int totalPage = 1;

    /**
     * 当前第几页
     */
    private int currentPage = 1;

    /**
     * 每页显示多少条记录
     */
    private int pageSize = 10;

    /**
     * 请求时的参数对象,页面可通过该对象获取搜索的条件
     */
    private T entity;

    /**
     * 其它要返回的对象
     */
    private Object obj;

    /**
     * 页面显示的数据集
     */
    private List<T> entityList;

    /**
     * map数据集
     */
    private List<Map<String, T>> mapList;

    public int getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
    }

    public int getTotalPage() {
        if (totalRecord % pageSize > 0) {
            return totalRecord / pageSize + 1;
        } else {
            return totalRecord / pageSize;
        }
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public T getEntity() {
        return entity;
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }

    public List<T> getEntityList() {
        return entityList;
    }

    public void setEntityList(List<T> entityList) {
        this.entityList = entityList;
    }

    public List<Map<String, T>> getMapList() {
        return mapList;
    }

    public void setMapList(List<Map<String, T>> mapList) {
        this.mapList = mapList;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }

    @Override
    public String toString() {
        return "PageReturn [totalRecord=" + totalRecord + ", totalPage=" + getTotalPage() + ", currentPage="
                + currentPage + ", pageSize=" + pageSize + ", entity=" + entity + ", obj=" + obj + ", entityList="
                + entityList + ", mapList=" + mapList + "]";
    }

}
